import { Login, User } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 登录模块
 */
// 用户登录
export const loginApi = (params: Login.ReqLoginForm) => {
  return http.post<Login.ResLogin>(PORT1 + `/user/login`, params, { loading: false });
};

// 用户注册
export const registerApi = (params: User.ReqRegister) => {
  return http.post<User.ResUserInfo>(PORT1 + `/user/register`, params);
};

// 检查登录状态
export const checkAuthApi = (params: Login.ReqLoginForm) => {
  return http.get<Login.ResCheckAuth>(PORT1 + `/user/auth/check`, params, { loading: false });
};

// 获取用户信息
export const getUserInfoApi = () => {
  return http.get<User.ResUserInfo>(PORT1 + `/user/getUserInfo`);
};

// 刷新Token
export const refreshTokenApi = (params: User.ReqRefreshToken) => {
  return http.post<User.ResRefreshToken>(PORT1 + `/user/refresh`, params);
};

// 用户退出登录
export const logoutApi = (params: User.ReqLoginout) => {
  return http.post(PORT1 + `/user/logout`, params);
};

/**
 * @name 权限模块
 */
// 获取菜单列表
export const getAuthMenuListApi = () => {
  return http.get<Menu.MenuOptions[]>(PORT1 + `/user/route/menu`);
};
